#include "SMPPQueryBroadcastSMResp.hpp"

using namespace smpp::pdu;

QueryBroadcastSMResp::QueryBroadcastSMResp(
const Header &nHeader,
const CoctetString &nMessageId,
const MessageState *nMessageState,
const QVector<BroadcastAreaIdentifier> nBroadcastAreaIdentifier,
const BroadcastAreaSuccess *nBroadcastAreaSuccess,
const QueryBroadcastResponseOptionalTLVs &nQueryBroadcastResponseOptionalTLVs):
Header(nHeader),
_MessageId(nMessageId),
_MessageState(0),
_BroadcastAreaIdentifier(nBroadcastAreaIdentifier),
_BroadcastAreaSuccess(0),
QueryBroadcastResponseOptionalTLVs(nQueryBroadcastResponseOptionalTLVs){
	if(nMessageState)
		_MessageState = 
		new MessageState(*nMessageState);
	if(nBroadcastAreaSuccess)
		_BroadcastAreaSuccess = 
		new BroadcastAreaSuccess(*nBroadcastAreaSuccess);
}

QueryBroadcastSMResp::QueryBroadcastSMResp(
const QueryBroadcastSMResp &nQueryBroadcastSMResp):
Header(nQueryBroadcastSMResp),
_MessageId(nQueryBroadcastSMResp.getMessageId()),
_MessageState(0),
_BroadcastAreaIdentifier(
nQueryBroadcastSMResp.getBroadcastAreaIdentifier()),
_BroadcastAreaSuccess(0),
QueryBroadcastResponseOptionalTLVs(nQueryBroadcastSMResp){
	if(nQueryBroadcastSMResp.getMessageState())
		_MessageState = 
		new MessageState(*nQueryBroadcastSMResp.getMessageState());
	if(nQueryBroadcastSMResp.getBroadcastAreaSuccess())
		_BroadcastAreaSuccess = 
		new BroadcastAreaSuccess(
		*nQueryBroadcastSMResp.getBroadcastAreaSuccess());
}

QueryBroadcastSMResp::~QueryBroadcastSMResp(){
	if(_MessageState)
		delete _MessageState;
	if(_BroadcastAreaSuccess)
		delete _BroadcastAreaSuccess;
}

void QueryBroadcastSMResp::setMessageId(
	const CoctetString &sMessageId){
	_MessageId = sMessageId;
}

const CoctetString &QueryBroadcastSMResp::getMessageId() const{
	return _MessageId;
}

void QueryBroadcastSMResp::setMessageState(
	const MessageState *nMessageState){
	if(_MessageState){
		delete _MessageState;
		_MessageState = 0;
	}
	if(nMessageState)
		_MessageState = 
		new MessageState(*nMessageState);
}

const MessageState *QueryBroadcastSMResp::getMessageState() const{
	return _MessageState;
}

void QueryBroadcastSMResp::addBroadcastAreaIdentifier(
	const BroadcastAreaIdentifier &nBroadcastAreaIdentifier){
	_BroadcastAreaIdentifier.push_back(nBroadcastAreaIdentifier);
}

void QueryBroadcastSMResp::setBroadcastAreaIdentifier(
	const QVector<BroadcastAreaIdentifier> &nBroadcastAreaIdentifier){
	_BroadcastAreaIdentifier = nBroadcastAreaIdentifier;
}

const QVector<BroadcastAreaIdentifier> &
	QueryBroadcastSMResp::getBroadcastAreaIdentifier() const{
	return _BroadcastAreaIdentifier;
}

void QueryBroadcastSMResp::setBroadcastAreaSuccess(
	const BroadcastAreaSuccess *nBroadcastAreaSuccess){
	if(_BroadcastAreaSuccess){
		delete _BroadcastAreaSuccess;
		_BroadcastAreaSuccess = 0;
	}
	if(nBroadcastAreaSuccess)
		_BroadcastAreaSuccess = 
		new BroadcastAreaSuccess(*nBroadcastAreaSuccess);
}

const BroadcastAreaSuccess *
	QueryBroadcastSMResp::getBroadcastAreaSuccess() const{
	return _BroadcastAreaSuccess;
}

void QueryBroadcastSMResp::calcCommandLength(){
	_CommandLength = 16 + _MessageId.size() +
		QueryBroadcastResponseOptionalTLVs::getLength();
	if(_MessageState)
		_CommandLength += _MessageState->getLength();
	for(int i = 0;i<_BroadcastAreaIdentifier.size();i++)
		_CommandLength += _BroadcastAreaIdentifier[i].getLength();
	if(_BroadcastAreaSuccess)
		_CommandLength += _BroadcastAreaSuccess->getLength();
}
